###R filename to compute the rejection frequencies
### filename is the output file of one the the programs Table4a.R, Table 4b.R or Table 4c.R
### It produces a table in tex format

variable <- commandArgs(trailingOnly=TRUE)
filename <- variable[1]

output <- read.table(filename, header = FALSE,sep = "")
output[1:2,1:20]
nblig<-nrow(output)
nbcol<-ncol(output)



nomstat<-c("$I_t$","$e_t$","$e_t^*$","$e_t^c$","$e_te_{t-1}$","$e_te_t{t-2}$","$e_te_{t-3}$",
                          "$me_3$","$e_t^*e_{t-1}^*$","$e_t^*e_t{t-2}^*","$e_t^*e_{t-3}^*$",
                          "$me-st-_3$","$e_t^ce_{t-1}^c$","$e_t^ce_t{t-2}^c","$e_t^ce_{t-3}^c$")
lissize=c(100,250,500)
lisstat=c(2,3,4,5,6,7,9,10,11,13,14,15)# Statistics displayed in the table
outputtable<-matrix(rep(NA,length(lissize)*length(lisstat)),ncol=length(lissize))
colnames(outputtable) <-as.character(lissize)
rownames(outputtable)<-nomstat[lisstat]
for (i in 1:length(lissize)){
    ns=lissize[i]
    matresul=subset(output,output[,4]==ns)
    for(ss in 1:length(lisstat)){
      ncolloc=lisstat[ss]+5
      outputtable[ss,i]=mean(matresul[,ncolloc]>3.84)*100
    }
}

library(xtable)
outputfile=paste(filename,".tex",sep="")
#print(xtable(outputtable),digits=2,file=outputfile)
toto=noquote(formatC(outputtable,digits=2,format="f"))
write.csv(toto, file = outputfile)

